import logging

import allure

from config.config import BASE_URL
from utils.ocr_utils import ocr

def analyse_case(case):
    with allure.step("解析请求数据"):
        logging.info(f"解析请求数据,根据{case}解析请求数据")
        method = case["method"]
        url = BASE_URL+ case["path"]
        if isinstance(case["headers"], str):
            headers = eval(case["headers"])
        else:
            headers = None

        if isinstance(case["params"], str):
            params = eval(case["params"])
        else:
            params = None

        if isinstance(case["data"], str):
            data = eval(case["data"])
        else:
            data = None

        if isinstance(case["json"], str):
            json = eval(case["json"])
        else:
            json = None

        if isinstance(case["files"], str):
            files = eval(case["files"])
        else:
            files = None

        request_data = {
            "method": method,
            "url": url,
            "headers": headers,
            "params": params,
            "data": data,
            "json": json,
            "files": files
        }
        logging.info(f"解析请求数据,请求数据为:{request_data}")
        allure.attach(f"{request_data}",name="解析数据结果")
        return request_data